<?php

namespace Kunfeng\Dify\Model\Chat;

/**
 * 应用信息响应模型
 */
class AppInfoResponse
{
    private $name;
    private $description;
    private $icon;
    private $mode;
    private $status;
    private $createdAt;
    private $updatedAt;

    public function __construct(
        string $name,
        ?string $description = null,
        ?string $icon = null,
        ?string $mode = null,
        ?string $status = null,
        ?int $createdAt = null,
        ?int $updatedAt = null
    ) {
        $this->name = $name;
        $this->description = $description;
        $this->icon = $icon;
        $this->mode = $mode;
        $this->status = $status;
        $this->createdAt = $createdAt;
        $this->updatedAt = $updatedAt;
    }

    /**
     * 从数组创建响应
     */
    public static function fromArray(array $data): self
    {
        return new self(
            $data['name'] ?? '',
            $data['description'] ?? null,
            $data['icon'] ?? null,
            $data['mode'] ?? null,
            $data['status'] ?? null,
            $data['created_at'] ?? null,
            $data['updated_at'] ?? null
        );
    }

    /**
     * 转换为数组
     */
    public function toArray(): array
    {
        $data = ['name' => $this->name];

        if ($this->description !== null) {
            $data['description'] = $this->description;
        }
        if ($this->icon !== null) {
            $data['icon'] = $this->icon;
        }
        if ($this->mode !== null) {
            $data['mode'] = $this->mode;
        }
        if ($this->status !== null) {
            $data['status'] = $this->status;
        }
        if ($this->createdAt !== null) {
            $data['created_at'] = $this->createdAt;
        }
        if ($this->updatedAt !== null) {
            $data['updated_at'] = $this->updatedAt;
        }

        return $data;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function getIcon(): ?string
    {
        return $this->icon;
    }

    public function getMode(): ?string
    {
        return $this->mode;
    }

    public function getStatus(): ?string
    {
        return $this->status;
    }

    public function getCreatedAt(): ?int
    {
        return $this->createdAt;
    }

    public function getUpdatedAt(): ?int
    {
        return $this->updatedAt;
    }
}
